package com.ss.demo.springbootdemo.aspect;

import com.ss.demo.springbootdemo.annotation.PermissionVerfiy;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 作者: MrZhangJR
 * 时间: 2021/11/3 14:04
 * 描述:
 */
@Aspect
@Component
public class PayAspect {

    @Pointcut("@annotation(com.ss.demo.springbootdemo.annotation.PermissionVerfiy)")
    public void operation(){};

    @Around("operation()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Method method = methodSignature.getMethod();
        PermissionVerfiy annotation = method.getAnnotation(PermissionVerfiy.class);
        if (annotation.value().equals("zjr")) {
            System.out.println("验证通过...");
            Object proceed = pjp.proceed();
            System.out.println("proceed = " + (String) proceed);
            return "success";
        }
        return "fail";
    }


}
